Usually we want to create automatically subtasks in a transition and sometimes with a specific label. We use usually the plugin Adaptavist Scriptrunner in Jira Server to do tasks like this. Just creating a Postfunction in the Workflow.

Captura de pantalla 2019-03-24 a las 13.14.47

We can use the “Create Sub-task” script Postfunction with the usual parameters…

Captura de pantalla 2019-03-24 a las 13.15.59

 

In the “additional issue actions” section add something like this


import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.label.LabelManager
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.ApplicationUser

def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
issue.summary = "Project "+issue.projectObject.name+" task with name " + sourceIssue.summary
doAfterCreate = {
def labelManager = ComponentAccessor.getComponent(LabelManager)
labelManager.addLabel(ComponentAccessor.jiraAuthenticationContext.getLoggedInUser(), issue.getId(), "TASK_LABEL", false)
}

Captura de pantalla 2019-03-24 a las 13.17.40

IMPORTANT NOTE:

Usually when we add a label the ticket must be created previously, for this reason the problem should be the “additional code” section runs before the issue is actually created.

You could try to put in the code in a “doAfterCreate” closure the “add label part“:

doAfterCreate {
  // add label
}

By MrAddon

.'s avatar
Posted by:.

One thought on “Create sub-task with specific label with Scriptrunner and Jira Server

Leave a comment